package com.admin.dao;

import com.admin.entity.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author szy
 * @since 2023-02-21
 */
public interface RoleMapper extends BaseMapper<Role> {

    /*查询角色数量*/
    @Select("select count(1) from user_role_relation where role_id=#{roleId}")
    int getRoleCountByRoleId(Long id);

    /*删除角色-权限关系*/
    @Delete("delete from role_permission_relation where role_id = #{id}")
    void deleteRolePermissionByRoleId(Long id);

    /*保存角色权限关系*/
    int saveRolePermission(Long roleId,List<Long> permissionIds);

    /*根据用户id查询该用户拥有的角色信息*/
    @Select("select role_id from user_role_relation where user_id=#{userId}")
    List<Long> findRoleIdByUserId(Long userId);
}
